#ifndef PRYN_GUI_PLATFORM_WINDOWS_H
#define PRYN_GUI_PLATFORM_WINDOWS_H

#define PrynGuiInternal
#define PrynGuiImplementation
#include <pryn.h>
#include <prynGui.h>
#include <windows.h>
#include <windowsx.h>

#ifdef __DMC__ /* DigitalMars C Compiler - some missing junk from its headers. */
#define CLEARTYPE_QUALITY 5

typedef struct
{
	DWORD cbSize;
	RECT rcWindow;
	RECT rcClient;
	DWORD dwStyle;
	DWORD dwExStyle;
	DWORD dwWindowStatus;
	UINT cxWindowBorders;
	UINT cyWindowBorders;
	ATOM atomWindowType;
	WORD wCreatorVersion;
} WINDOWINFO, *PWINDOWINFO, *LPWINDOWINFO;

WINUSERAPI BOOL WINAPI GetWindowInfo (HWND hwnd, PWINDOWINFO pwi);

#define IDC_HAND MAKEINTRESOURCE (32649)
#define WS_EX_COMPOSITED 0x02000000L
#define WS_EX_LAYERED 0x00080000L
#define LWA_ALPHA 0x00000002
#define UINT_PTR uintptr_t
#endif /* __DMC__ */

typedef struct PrynGuiPainterWindows PrynGuiPainterWindows;
typedef struct PrynGuiStateWindows PrynGuiStateWindows;

#define PrynGuiStateWindowsTagId "PrynGui.StateWindows"

/// Information attached to the PrynState under a PrynGuiStateWindowsTagId tag.
struct PrynGuiStateWindows
{
	HMODULE libraryGdi32; /// Handle to gdi32.dll, or 0 if it could not be loaded.
	HPEN (WINAPI *ExtCreatePen) (DWORD dwPenStyle, DWORD dwWidth, const LOGBRUSH *lplb, DWORD dwStyleCount, const DWORD *lpStyle);
	HBITMAP (WINAPI *CreateDIBitmap) (HDC hdc, const BITMAPINFOHEADER *lpbmih, DWORD fdwInit, const VOID *lpbInit, const BITMAPINFO *lpbmi, UINT fuUsage);
	BOOL (WINAPI *PlgBlt) (HDC hdcDest, const POINT *lpPoint, HDC hdcSrc, int nXSrc, int nYSrc, int nWidth, int nHeight, HBITMAP hbmMask, int xMask, int yMask);
	
	ATOM windowClass; /// Class to use for windows, or 0 if it hasn't been allocated yet.
	HINSTANCE instance;
	bool quitLoop; /// Quit the message loop.
};

/// Painter state for Windows.
struct PrynGuiPainterWindows
{
	PrynGuiStateWindows *api;
	HWND window;
	HDC windowDevice;
	
	HDC device;
	HBITMAP bitmap;
	
	HBRUSH brush;
	bool brushAllocated;
	
	HPEN pen;
	bool penAllocated;
	HBITMAP penBitmap;
	int penBitmapWidth, penBitmapHeight;
	int penWidth;
	bool penFake;
	int penOffset;
	
	PrynGuiTextAlign align;
	
	LOGFONTA font;
	bool fontDirty;
	HFONT fontObject;
};

PrynGuiImport (PrynResult, prynGuiStateWindows, (PrynGuiStateWindows **api, PrynState *state)) /// Return the windows GUI state, creating it if necessary.

#endif /* PRYN_GUI_PLATFORM_WINDOWS_H */
